# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file '使用fontcombobox改变字体.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
import sys
from PySide2 import QtGui, QtCore, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.fontComboBox = QFontComboBox(self.centralwidget)
        self.fontComboBox.setObjectName(u"fontComboBox")
        self.fontComboBox.setGeometry(QRect(240, 160, 271, 61))

        # 为fontcombobox设置要显示的字体以及信号与槽的关联
        self.fontComboBox.setFontFilters(QtWidgets.QFontComboBox.AllFonts)
        self.fontComboBox.currentIndexChanged.connect(self.setfont)

        self.label = QLabel(self.centralwidget)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(250, 270, 251, 41))
        self.label.setAlignment(Qt.AlignCenter)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 800, 26))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u52a8\u6001\u6539\u53d8\u6807\u7b7e\u7684\u5b57\u4f53", None))
        self.label.setText(QCoreApplication.translate("MainWindow", u"\u5b57\u4f53\u663e\u793a\u533a\u57df", None))
    # retranslateUi

    # 自定义槽函数，用来将选择的字体设置为label标签的字体
    def setfont(self):
        print(self.fontComboBox.currentText())      # 在控制台中输出选择的字体
        self.label.setFont(QtGui.QFont(self.fontComboBox.currentText()))


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())



